package com.bazaaroid.server.gae.api.resources.partner;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.bazaaroid.server.gae.core.dao.partner.TagDAO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO;
import com.bazaaroid.server.gae.core.dto.partner.TagDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO.TagsDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;
import com.bazaaroid.server.gae.core.persistence.model.partner.Tag;
import com.google.appengine.api.datastore.KeyFactory;

@Path("/tag/")
public class TagResource {

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/{id}")
	public TagDTO getById(@PathParam ("id") Long id) {
		TagDAO tagDAO = GuiceFactory.getInjector().getInstance(TagDAO.class);
		Tag tag = tagDAO.getById(KeyFactory.createKey(Tag.class.getSimpleName(), id));
		return new TagDTO(tag);
	}

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/all/")
	public TagsDTO getAllTags() {
		TagDAO tagDAO = GuiceFactory.getInjector().getInstance(TagDAO.class);
		List<Tag> tags = tagDAO.getAll();
		return new AllEntitiesDTO.TagsDTO(tags);
	}
}
